<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <blockquote class="layui-elem-quote">
            <h1>入社审批</h1>
        </blockquote>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 同意 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 拒绝 </button>
            </div>
        </script>


        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/select/peopleAssociation/get',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
               {type: "checkbox", width: 50},
                              {field: 'peopleNumber', width: 125, title: '学号/工号', sort: true},
                              {field: 'peopleName', width: 80, title: '姓名'},
                              {field: 'peopleGender', width: 80, title: '性别', sort: true},
                              {field: 'peopleAge', width: 80, title: '年龄'},
                              {field: 'peopleClass',width:130, title: '班级', sort: true},
                              {field: 'peoplePhone', width: 150, title: '手机号', sort: true},
                              {field: 'peopleRank', width: 135, title: '身份', sort: true},
                              {field: 'communityName', width: 135, title: '加入社团名'},
                              {field: 'peopleStatus', width: 135, title: '状态', sort: false,templet:function (d) {
                                      if(d.peopleStatus == '1'){
                                          e= '<span class="layui-badge">申请中...</span>';
                                          return e;
                                      }

                                  }},
            ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 20,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(da ta-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听同意操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;

                for(var i in data){//暂时使用单修改接口，后期修改
                    $.ajax({//发送进行修改状态
                        url:'/people/apply/pass',
                        type:'GET',
                        data:{peopleNumber:data[i].peopleNumber},
                        success:function(data){

                            table.render(); //更新全部表单内容
                        }
                    });
                }
                location.reload();//刷新主页表格
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;

                for(var i in data){//暂时使用单个删除接口，后期修改
                    $.ajax({//发送进行删除
                        url:'/people/apply/no',
                        type:'GET',
                        data:{peopleNumber:data[i].peopleNumber},
                        success:function(data){


                            table.render(); //更新全部表单内容
                        }
                    });
                }
                location.reload();//刷新主页表格
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

    });
</script>

</body>
</html>